﻿var weekWidth = '168px';
var leftIndex = 1;
var rightIndex = 5;
var main = true;

$(document).ready(function () {

    hideTables();

    $("#btn_left").click(function() {
        if (weeks > 5) {
            if (rightIndex != weeks) {
                $("#table_" + leftIndex).animate({ 'margin-left': '-168px' }, 500).fadeOut(500);
                $("#table_" + (rightIndex + 1)).fadeIn(500);
                leftIndex++;
                rightIndex++;
            }
        }
    });

    $("#btn_right").click(function () {
        if (weeks > 5) {
            if (leftIndex != 1) {
                $("#table_" + (leftIndex - 1)).animate({ 'margin-left': '0' }, 500).show();
                $("#table_" + rightIndex).fadeOut(500);
                leftIndex--;
                rightIndex--;
            }
        }
    });

    $('#addWeekMainBtn').click(function () {
        $("#weekAmount").css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' }).val("");
        $('#addWeekPop, #overlay').fadeIn(1000);
    });

    $('.closeWeekPop').click(function () {
        $('#addWeekPop, #overlay').fadeOut(1000);

    });
});

function hideTables() {
    if (weeks > 5) {
        for (var i = 6; i <= weeks; i++) {
            $("#table_" + i).hide();
        }
    }
}

function redirectToDeetailedView(url) {
    window.location.href = url;
}

function validateWeek() {
    var selector = $("#weekAmount");
    var regex = new RegExp("[0-9]+$");
    if (regex.test(selector.val())) {
        if (parseInt(selector.val()) <= 0 || parseInt(selector.val()) > 53 || selector.val() == "" || selector.val.length > 2) {
            selector.css({ 'background': 'url("../Resources/img/main/inputErr.png") no-repeat' });
            return false;
        } else {
            selector.css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' });
            return true;
        }
    }
    selector.css({ 'background': 'url("../Resources/img/main/inputErr.png") no-repeat' });
    return false;
}